package com.example.practical_training_projects.service;

import com.example.practical_training_projects.entity.Gets;
import com.example.practical_training_projects.mapper.GetsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GetsServiceImpl implements GetsService {
    @Autowired
    private GetsMapper getsMapper;

    @Override
    public void toggleGet(Integer userUid, String contentType, Integer contentUid) {
        if (getsMapper.countGets(contentType, contentUid) > 0) {
            getsMapper.deleteGet(userUid, contentType, contentUid);
        } else {
            Gets newGet = new Gets();
            newGet.setUserUid(userUid);
            newGet.setContentType(contentType);
            newGet.setContentUid(contentUid);
            getsMapper.insertGet(newGet);
        }
    }

    @Override
    public int getGetsCount(String contentType, Integer contentUid) {
        return getsMapper.countGets(contentType, contentUid);
    }
}
